import city from './city'
var domestic = city.domestic;/*一个对象*/
var abroad = city.abroad/*一个对象*/

var cityOption = load()
var areaOption = loadDomestic(true)
var domesticOption = loadDomestic(false)

//加载国外的数组
function load() {
  var list = []
  abroad.forEach(e => {
    if (e.cn === '中国') {
      var children = loadDomestic()/*区域*/
      list.push({
        label: e.cn,
        value: e.cn,
        children: children
      })
    } else {
      list.push({
        label: e.cn,
        value: e.cn
      })
    }
  })
  return list;
}

//加载国内数组
function loadDomestic(type) {
  let list = []
  for (var key in domestic) {
    var children = loadCity(domestic[key], type);
    list.push({
      label: key,
      value: key,
      children: children
    })
  }
  return list
}

//加载国内市区
function loadCity(citys, type) {
  var list = []
  for (var key in citys) {
    if (type) {
      let children = loadArea(citys[key])
      list.push({
        label: key,
        value: key,
        children: children
      })
    } else {
      list.push({
        label: key,
        value: key,
      })
    }
  }
  return list;
}

//加载国内地区
function loadArea(areas) {
  var list = []
  areas.forEach(e => {
    list.push({
      label: e,
      value: e
    })
  })
  return list
}

//导出
export default {
  cityOption: cityOption,/*一个数组*/
  areaOption: areaOption,/*一个数组*/
  domesticOption: domesticOption/*一个数组*/
}
